/////////////////////////////////////////////////
repo:    cdriven6x
target:  comment_driven
branch:  6.x-1.x
tags:    
node:    b9603d9b669d1dc5b682c3a5faa59361de832ae1
changes:
* theme_comment_driven_proxy (expected to fix [#761288] & [#768202] altogether)
/////////////////////////////////////////////////
=================================================
message: theme_comment_driven_proxy (expected to fix [#761288] & [#768202] altogether)
branch:  6.x-1.x
tags:    tip
node:    57b24f1ad71709f5e060ab1ae4b49e85a9e2e90b
=================================================
diff -r b9603d9b669d -r 57b24f1ad717 comment_driven/comment_driven.module
--- comment_driven.module	Mon Apr 12 23:20:58 2010 -0500
+++ comment_driven.module	Mon Apr 12 23:22:28 2010 -0500
@@ -83,6 +83,17 @@ function comment_driven_node_type($op, $
   }
 }
 
+/**
+ * Implements hook_theme().
+ */
+function comment_driven_theme() {
+  return array(
+    'comment_driven_proxy' => array(
+      'arguments' => array('element' => NULL),
+    ),
+  );
+}
+
 ///\\\///\\\///\\\///\\\///
 
 /**
@@ -191,7 +202,10 @@ function comment_driven_is_live_render($
 
 function _comment_driven_disguise_children($element) {
   // @TODO: every call to comment_driven_assertion_failed will be removed after alpha/beta stage 
-  if (!is_array($element)) comment_driven_assertion_failed('something nasty is happening somewhere: !is_array($element)');
+  if (!is_array($element)) {
+    comment_driven_assertion_failed('something nasty is happening somewhere: !is_array($element)');
+    return;
+  }
   
   // adjust #parents to match the disguised elements of comment_form
   // note that no parent would point to a level above the comment_form
@@ -208,7 +222,16 @@ function _comment_driven_disguise_childr
     // protect ourself against 3rd parties creating NULL children (e.g. [#736968], [#737044])
     // lets babysit NULL children, but it has to be an array otherwise
     if (!is_null($element[$key])) {
-      $element[COMMENT_DRIVEN__DISGUISE_PREFIX . $key] = _comment_driven_disguise_children($element[$key]);
+      $disguised_child = _comment_driven_disguise_children($element[$key]);
+      if (isset($disguised_child['#theme'])) {
+        // disguise_children supports only element_children
+        // (disguise_form_values doesn't address non-children either) 
+        // undisguise does support non-children as well
+        // manually disguise non-children
+        $disguised_child['#' . COMMENT_DRIVEN__DISGUISE_PREFIX . '#theme'] = $disguised_child['#theme'];
+        $disguised_child['#theme'] = 'comment_driven_proxy'; 
+      }
+      $element[COMMENT_DRIVEN__DISGUISE_PREFIX . $key] = $disguised_child;
     }
     // if it was NULL (above babysitting) won't hurt clearing it
     unset($element[$key]);
@@ -226,6 +249,14 @@ function _comment_driven_disguise_adjust
   }
 }
 
+function theme_comment_driven_proxy($element) {
+  // key #theme is expected to be overriden by its disguised version
+  // but, just in case, lets ensure we won't fall back here (unintended recursion) 
+  unset($element['#theme']);
+  $element = _comment_driven_undisguise($element);
+  return drupal_render($element);
+}
+
 // helper function to drive properties programmatically [#741274] 
 function comment_driven_disguise_form_values($arr) {
   // @TODO: every call to comment_driven_assertion_failed will be removed after alpha/beta stage 
/////////////////////////////////////////////////
generated with: drudiff cdriven6x comment_driven 173 174 
/////////////////////////////////////////////////
